package com.panshi.modules.common.question;

import com.panshi.IssApi;
import com.panshi.api.util.CommonResult;
import com.panshi.api.util.PageSizeVO;
import com.panshi.bean.IssBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author :jiege
 * @description :
 * @create :2020-08-15 09:38:00
 */
@Controller
@Api(tags = "问题页面接口")
public class QuestionController {

    @Autowired
    private IssApi issApi;

    @GetMapping("/question/list")
    @RequiresPermissions("question:list")
    @ApiOperation("问答页面")
    public String articlepage(){
        return "/question/question-list";
    }

    @GetMapping("/question/questionlist")
    @ResponseBody
    @RequiresPermissions("question:list")
    @ApiOperation("查询所有问答")
    public PageSizeVO<List<IssBean>> queryunanswerlist(Integer currentPage, Integer pageSize, String state){
        System.out.println(currentPage+"============"+pageSize);
        PageSizeVO<String> pageSizeBean = new PageSizeVO();
        pageSizeBean.setStartIndex(currentPage);
        pageSizeBean.setPageSize(pageSize);
        pageSizeBean.setState(state);
        return  issApi.adminFindAll(pageSizeBean);
    }

    @PostMapping("/question/updatelist")
    @ResponseBody
    @RequiresPermissions("question:update")
    @ApiOperation("修改问答问答")
    public CommonResult<String> updateanswerlist(int qid,int state,int tid) throws Exception {
        issApi.adminUpdateQa(qid,state,tid);
        return new CommonResult<>();
    }
}
